<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>订舱分票</title>
		<link rel="stylesheet" href="static/ace/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" />
		<link rel="stylesheet" type="text/css" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css">
		<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
</head>
<body>
<div id="selForm"></div>
</body>
<script type="text/javascript">
Ext.onReady(function(){
	var store = Ext.create('Ext.data.Store', {
		fields: ["ID",
		 		"BILL_CODE",
				"LADING_BILL_CODE",
				"IS_MAIN_LADING_BILL",
				"IS_CUSTOMS",
				"IS_SIGN_BILL",
				"BOX_MASTER_ID",
				"BOX_MASTER",
				"CREATETIME"],
		pageSize: 15,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>bookingCargoTickets/findBookingCargoTicketsInfo',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
			    root: 'result.list',  //数据
                totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var store1 = Ext.create('Ext.data.Store', {
		fields: ["ID",
		 		"BILL_CODE",
				"LADING_BILL_CODE",
				"IS_MAIN_LADING_BILL",
				"IS_CUSTOMS",
				"IS_SIGN_BILL",
				"BOX_MASTER_ID",
				"BOX_MASTER",
				"CREATETIME"],
		pageSize: 30,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>bookingCargoTickets/findBookingCargoTicketsInfoByBillCode',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'root1',  //数据
				totalProperty: 'total' //数据总条数
			}
		},
// 		sorters: [{
// 			property: 'ordeId',
// 			direction: 'desc'
// 		}],
// 		autoLoad: true
	});
	var insuranceStore = Ext.create('Ext.data.Store', {
		fields: ['id', 'name'],
		data : [
			{"id":"1", "name":"是"},
			{"id":"0", "name":"否"}
		]
	});
	  var paging = new Ext.PagingToolbar(
				{
					store : store,
					 pageSize:10,
					displayInfo : true,
					displayMsg : '<span style="color:blue;">第{0}条</span>至<span style="color:blue;">{1}条</span>，共<span style="color:blue;">{2}</span>条记录',
					emptyMsg : '无记录'
				});
	  
	  var c2 = Ext.create('Ext.container.Container', {
			layout: 'column',
			defaults: { labelAlign: 'left', labelWidth: 60 },
			items: [
				
{id:"startDate6",xtype: 'textfield', name: 'startDate6',columnWidth: 1/5,padding: '5px',fieldLabel: '托单编号'},
{id:"startDate7",xtype: 'textfield', name: 'startDate7', columnWidth:  1/5,padding: '5px', fieldLabel: '提单编号'},
{id:"startDate8",xtype: 'combobox', name: 'startDate8', columnWidth:  1/5,padding: '5px',store:insuranceStore,displayField: "name", valueField: "id",fieldLabel: '主提单标志'},,

			]
		});
	  var bs = Ext.create('Ext.container.Container', {
			layout: 'column',
			items: [
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,   padding: '10px'},
				{layout : 'column',baseCls : 'my-panel-no-border',columnWidth: 1/5,  padding: '10px',  items: [
					{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "查询",handler: function(){
			      		 var BILL_CODE = Ext.getCmp('startDate6').getValue();
				      		var LADING_BILL_CODE = Ext.getCmp('startDate7').getValue();
				      		var IS_MAIN_LADING_BILL = Ext.getCmp('startDate8').getValue();
				      		
					var store = Ext.getCmp('grid').getStore();
					store.on('beforeload', function(store,options) {  
				            var new_params = {  
				            		BILL_CODE : BILL_CODE, LADING_BILL_CODE:LADING_BILL_CODE,IS_MAIN_LADING_BILL:IS_MAIN_LADING_BILL
				            };  
					//这里apply一下实现新的proxy  
				            Ext.apply(store.proxy.extraParams,new_params);  
				        });  
					//对store重新载入  
				        store.load();  


							
				      	 } },
				],},
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,  padding: '10px'}
			]
		});
	  var tbtn4 = Ext.create("Ext.Button", {
		  text:"修改",
		  handler:function(){
			  var records = grid.getSelectionModel().getSelection();
			   	 		if(records.length==0){
			     			Ext.Msg.alert("提示","请选择一条记录");return;
			     		}
			     		if(records.length>1){
			     			Ext.Msg.alert("提示","只能编辑一条记录");return;
			     		}
			     		
			     		var store = Ext.getCmp('grid1').getStore();
						store.on('beforeload', function(store,options) {  
					            var new_params = {  
					            		BILL_CODE:records[0].data.BILL_CODE	
					            };  
						//这里apply一下实现新的proxy  
					            Ext.apply(store.proxy.extraParams,new_params);  
					        });  
						//对store重新载入  
					        store.load();  
			     		var needful = {
			   					xtype: 'form',
			   					id:'form',
// 			   					title: '必填信息',
			   					 layout:'column',
			   					 height: 150,
			   					//collapsible: true,
			   					//collapsed: false,
			   					 region:'center',  
							    //内容溢出自动滚动  
							    autoScroll:true, 
			   					fieldDefaults: {
//		 				        			labelWidth: 90,
	 				        			labelAlign: "left",
	 				        			//flex: 1,
//		 				        			margin: 5,
										margin : '10 10 10 10',
	 				        			labelStyle: 'color:green;'
	 				        		},
			   					margin: 2,
			   					padding:0,
			   					items: [{
	   					        	id:"ID",
   					        		xtype: 'textfield',
   					        		name: 'ID',
   					        		hidden: true, 
   					        		hideLabel:true,
   					        		fieldLabel: 'ID',
   					        		value:records[0].data.ID,
//	   					        		allowBlank:false
   					        	},{
//	   					        		id："ID",
   					        		xtype: 'textfield',
   					        		name: 'BILL_CODE',
   					        		fieldLabel: '托单编号',
   					        		columnWidth:1/3,
   					        		value:records[0].data.BILL_CODE,
   					        		readOnly: true,
   					                allowBlank: false,
   					        	},
   					        	{
//   					        		id："ID",
					        		xtype: 'textfield',
					        		name: 'LADING_BILL_CODE',
					        		fieldLabel: '提单编号',
					        		value:records[0].data.LADING_BILL_CODE,
					                
									columnWidth:1/3,
					                
					        	},,{
//	   					        		id："ID",
   					        		xtype: 'textfield',
   					        		name: 'BOX_MASTER',
   					        		fieldLabel: '箱主',
   					        		columnWidth:1/3,
   					        		value:records[0].data.BOX_MASTER,
   					        		readOnly: true,
   					                allowBlank: false,
   					        	},{
					                xtype: 'radiogroup',    
					                fieldLabel: '主提单标志',     
					                layout: 'auto',
					                id:'IS_MAIN_LADING_BILL',
					                columnWidth:1/3,
					                value:records[0].data.IS_MAIN_LADING_BILL,
//						                columns: 3,     
					                items: [     
// 					                    {name: 'rg',boxLabel: '是',inputValue:0,id:'IS_MAIN_LADING_BILLis'},     
// 					                    {name: 'rg',boxLabel: '否',inputValue:1,id:'IS_MAIN_LADING_BILLnot'},     
												new Ext.form.Radio({
												    id:"titleid",
												    name:"operator3",
												    inputValue:"1",
												    boxLabel:'是',
												    readOnly : true,
												    
												}),new Ext.form.Radio({
												    id:"textid",
												    name:"operator3",
												    inputValue:"0",
												    readOnly : true,
												    boxLabel:'否'
												}),
					                ],
					        	},{
					                xtype: 'radiogroup',    
					                fieldLabel: '报关标志',     
					                layout: 'auto',
					                id:'IS_CUSTOMS',
					                columnWidth:1/3,
					                value:records[0].data.IS_CUSTOMS,
//						                columns: 3,     
					                items: [     
// 					                    {name: 'cu',boxLabel: '是',inputValue:0},     
// 					                    {name: 'cu',boxLabel: '否',inputValue:1},  
											new Ext.form.Radio({
											    id:"cu1",
											    name:"operator2",
											    inputValue:"1",
											    boxLabel:'是',
											    
											}),new Ext.form.Radio({
											    id:"cu2",
											    name:"operator2",
											    inputValue:"0",
											    boxLabel:'否'
											}),

					                ],
					        	},{
					                xtype: 'radiogroup',    
					                fieldLabel: '签单标志',     
					                layout: 'auto',
					                id:'IS_SIGN_BILL',
					                columnWidth:1/3,
					                value:records[0].data.IS_SIGN_BILL,
//						                columns: 3,     
					                items: [     
// 					                    {name: 'sb',boxLabel: '是',inputValue:0},     
// 					                    {name: 'sb',boxLabel: '否',inputValue:1},     
										new Ext.form.Radio({
										    id:"sb1",
										    name:"operator1",
										    inputValue:"1",
										    boxLabel:'是',
										    
										}),new Ext.form.Radio({
										    id:"sb2",
										    name:"operator1",
										    inputValue:"0",
										    boxLabel:'否'
										}),
					                ],
					        	}],
	 				        		
			     		}
			     		 
			     		if(records[0].data.IS_MAIN_LADING_BILL=="是"){
// 			     			Ext.getCmp("titleid").checked = true;
			     			 Ext.getCmp('titleid').setValue(true);
			     		}else{
// 			     		   Ext.getCmp("textid").checked = true;
			     		  Ext.getCmp('textid').setValue(true);
			     		}
			     		if(records[0].data.IS_CUSTOMS=="是"){
// 			     			Ext.getCmp("cu1").checked = true;
			     			 Ext.getCmp('cu1').setValue(true);
			     		}else{
// 			     			Ext.getCmp("cu2").checked = true;
			     			 Ext.getCmp('cu2').setValue(true);
			     		}
			     		if(records[0].data.IS_SIGN_BILL=="是"){
// 			     			Ext.getCmp("sb1").checked = true;
			     			 Ext.getCmp('sb1').setValue(true);
			     		}else{
// 			     			Ext.getCmp("sb2").checked = true;
			     			 Ext.getCmp('sb2').setValue(true);
			     		}
			     		var edit = {
			   					xtype: 'form',
			   					id:'form1',
			   					title: '新增分票',
			   					 layout:'column',
			   					 height: 150,
			   					//collapsible: true,
			   					//collapsed: false,
			   					 region:'center',  
							    //内容溢出自动滚动  
							    autoScroll:true, 
			   					fieldDefaults: {
//		 				        			labelWidth: 90,
	 				        			labelAlign: "left",
	 				        			
	 				        			//flex: 1,
//		 				        			margin: 5,
										margin : '10 10 10 10',
	 				        			labelStyle: 'color:green;'
	 				        		},
			   					margin: 2,
			   					padding:0,
			   					items: [
   					        	{
//   					        		id："ID",
					        		xtype: 'textfield',
					        		columnWidth:1/3,
					        		id:'billCode1',
					        		name: 'billCode1',
					        		fieldLabel: '提单编号',
					        		blankText : '提单编号不能为空', 
					                allowBlank: false,
// 					        		value:records[0].data.BILL_CODE,
					        	},{
					                xtype: 'radiogroup',    
					                fieldLabel: '报关标志', 
					                columnWidth:1/3,
					                layout: 'auto',
					                name:'IS_CUSTOMS1',
					                id:'IS_CUSTOMS1',
// 					                value:records[0].data.IS_CUSTOMS,
//						                columns: 3,     
					                items: [     
// 					                    {name: '1',boxLabel: '是',inputValue:0},     
// 					                    {name: '2',boxLabel: '否',inputValue:1},     
										new Ext.form.Radio({
										    id:"sb3",
										    name:"operator4",
										    inputValue:"1",
										    boxLabel:'是',
										    
										}),new Ext.form.Radio({
										    id:"sb4",
										    name:"operator4",
										    inputValue:"0",
										    boxLabel:'否'
										}),

					                ],
					        	},{
					                xtype: 'radiogroup',    
					                fieldLabel: '签单标志', 
					                columnWidth:1/3,
					                layout: 'auto',
					                id:'IS_SIGN_BILL1',
					                name:'IS_SIGN_BILL1',
// 					                value:records[0].data.IS_SIGN_BILL,
//						                columns: 3,     
					                items: [     
// 					                    {name: '1',boxLabel: '是',inputValue:0},     
// 					                    {name: '2',boxLabel: '否',inputValue:1},     
										new Ext.form.Radio({
										    id:"sb5",
										    name:"operator5",
										    inputValue:"1",
										    boxLabel:'是',
										    
										}),new Ext.form.Radio({
										    id:"sb6",
										    name:"operator5",
										    inputValue:"0",
										    boxLabel:'否'
										}),
					                ],
					        	}],
	 				        		
			     		}
			     		var win = Ext.create("Ext.window.Window", {
						    title: '修改订舱分票信息',
						    width: '80%',
						    height: '45%',
						   resizable: true,
						    modal: true,
						   closable: true,
						   maximizable: true,
						   minimizable: true,
						   closeAction :'hide',
//			 			   buttons:[save1,clear1,close1],
						   items:[needful,edit,grid1],
						   buttons: [{
		       		            text: '保存',
		       		            handler: function(){
		       		            	if(Ext.getCmp('billCode1').getValue()==null || Ext.getCmp('billCode1').getValue()==""){
		       		            		Ext.Msg.alert("提示","提单编号不能为空!");
		       		            		return false;
		       		            	}
		       		            	
		       		            	var arr = [];
		       		            	var form = Ext.getCmp('form').getForm();
		       		            	var form1 = Ext.getCmp('form1').getForm();
		       		            	
		       		            	obj={ID:form.findField('ID').value,
		       		            		BILL_CODE:form.findField('BILL_CODE').value,
		       		            		LADING_BILL_CODE:form.findField('LADING_BILL_CODE').value,
		       		            		IS_MAIN_LADING_BILL:form.getValues().operator3,
		       		            		IS_CUSTOMS:form.getValues().operator2,
		       		            		IS_SIGN_BILL:form.getValues().operator1,
		       		            		BOX_MASTER:form.findField('BOX_MASTER').value,
		       		            	}
		       		            	obj1 = {
		       		            			ID:"",
			       		            		BILL_CODE:form.findField('BILL_CODE').value,
			       		            		LADING_BILL_CODE:Ext.getCmp('billCode1').getValue(),
			       		            		IS_MAIN_LADING_BILL:form.getValues().operator3,
			       		            		IS_CUSTOMS:form1.getValues().operator4,
			       		            		IS_SIGN_BILL:form1.getValues().operator5,
			       		            		BOX_MASTER:form.findField('BOX_MASTER').value,
		       		            			
		       		            	}
// 		       		            	for (var i=0;i<formVlaue.length;i++)
// 		       		            	{
// 		       		            		obj={
		       		            				
		       		            				
// 		       		            		}
		       		            		
// 		       		            		alert(formVlaue[i].value);
// 		       		            		arr.push(obj);
// 		       		            	}
		       		            	arr.push(obj)
		       		            	arr.push(obj1)
		       		            	var array = JSON.stringify(arr);
		       			       				
		       			       					Ext.Ajax.request({
		       			       						url:'<%=basePath%>bookingCargoTickets/saveAndUpdateInfo',
		       			       						params:{
		       			       							array:array
		       			       						},
		       			       						timeout:5000,
		       			       						success:function(response){
		       			       							store1.load();
		       			       						store.load();
		       			       							Ext.Msg.alert("成功","保存成功!");
		       			       						},
		       			       						failure:function(response){
		       			       							store1.load();
		       			       						store.load();
		       			       							Ext.Msg.alert("错误","请求异常!");
		       			       						}
		       			       					});
		       			       				
// 		       		            	form.submit({
// 		       		            		params:{
		       		            			
// 		       		            		},
// 		       		            		waitTitle : '请稍后...',  
// 		       		            		waitMsg : '正在保存信息,请稍后...',  
// 		       		            		url:'../consignHandle/saveAndUpdateInfo',
// 				          				success:function(form,action){
// 				          					Ext.Msg.alert("提示","保存成功");
// 				          					store.load();
// 				          					win.close();
// 				          				},

// 				          			});

		       		            }
		       		        },{
		       		            text: '关闭',
		       		            handler: function(){
		       		            	win.close();
		       		            }
		       		        }]
						});
			   	 		win.show(); 
		  }
	  });
		var deleteInfo =new Ext.Button({
			text: '删除',
			handler:function(){
	     		var records = grid1.getSelectionModel().getSelection();
	       			if(records.length==0){
	       				Ext.Msg.alert("提示","请选中需要删除的实体记录");return;
	       			}
	       			var arr = [];
	       			Ext.each(records,function(item){
	       				obj = {
	       						id:item.data.ID
	       				};
	       				arr.push(obj);
	       			});
	       			var array = JSON.stringify(arr);
	       			Ext.Msg.confirm("提示","确定删除数据?",function(btn){
		       				
		       					Ext.Ajax.request({
		       						url:'<%=basePath%>bookingCargoTickets/deleteInfo',
		       						params:{
		       							array:array
		       						},
		       						timeout:5000,
		       						success:function(response){
		       							store.load();
		       							store1.load();
		       							Ext.Msg.alert("成功","删除成功!");
		       						},
		       						failure:function(response){
		       							store.load();
		       							store1.load();
		       							Ext.Msg.alert("错误","请求异常!");
		       						}
		       					});
		       				
		       			});
	     	}
		});
		var deleteData =new Ext.Button({
			text: '删除',
			handler:function(){
	     		var records = grid.getSelectionModel().getSelection();
	       			if(records.length==0){
	       				Ext.Msg.alert("提示","请选中需要删除的实体记录");return;
	       			}
	       			if(records[0].data.IS_MAIN_LADING_BILL=="是"){
	       				Ext.Msg.alert("提示","不能删除主提单");return;
	       			}
	       			var arr = [];
	       			Ext.each(records,function(item){
	       				obj = {
	       						id:item.data.ID
	       				};
	       				arr.push(obj);
	       			});
	       			var array = JSON.stringify(arr);
	       			Ext.Msg.confirm("提示","确定删除数据?",function(btn){
		       				
		       					Ext.Ajax.request({
		       						url:'<%=basePath%>bookingCargoTickets/deleteInfo',
		       						params:{
		       							array:array
		       						},
		       						timeout:5000,
		       						success:function(response){
		       							store.load();
		       							store1.load();
		       							Ext.Msg.alert("成功","删除成功!");
		       						},
		       						failure:function(response){
		       							store.load();
		       							store1.load();
		       							Ext.Msg.alert("错误","请求异常!");
		       						}
		       					});
		       				
		       			});
	     	}
		});
		var grid = Ext.create('Ext.grid.Panel', {
			title:'订舱分票列表',
			store: store,
			id:'grid',			
			height: '70%',
			stripeRows:true,
			columnLines: true,
			bbar:paging,
			forceFit: true,
			tbar: [tbtn4,deleteData],
			selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
			columns: [
				{text: 'ID', dataIndex: 'ID',hidden:true},
				{text: '托单编号', dataIndex: 'BILL_CODE'},
				{text: '提单编号', dataIndex: 'LADING_BILL_CODE'},
				{text: '主提单标志', dataIndex: 'IS_MAIN_LADING_BILL'},
				{text: '报关标志', dataIndex: 'IS_CUSTOMS'},
				{text: '签单标志', dataIndex: 'IS_SIGN_BILL'},
				{text: '箱主', dataIndex: 'BOX_MASTER'},
			],
			item:[]
		});
		var grid1 = Ext.create('Ext.grid.Panel', {
			title:'订舱分票列表',
			store: store1,
			id:'grid1',			
			height: 200,
			stripeRows:true,
			columnLines: true,
// 			bbar:paging,
			forceFit: true,
			tbar: [deleteInfo],
			selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
			columns: [
{text: 'ID', dataIndex: 'ID',hidden:true},
{text: '托单编号', dataIndex: 'BILL_CODE'},
{text: '提单编号', dataIndex: 'LADING_BILL_CODE'},
{text: '主提单标志', dataIndex: 'IS_MAIN_LADING_BILL'},
{text: '报关标志', dataIndex: 'IS_CUSTOMS'},
{text: '签单标志', dataIndex: 'IS_SIGN_BILL'},
{text: '箱主', dataIndex: 'BOX_MASTER'},
			],
			item:[]
		});
		var selForm = Ext.create('Ext.form.Panel', {
			
			name: 'selForm',
			width:'100%',
			height:80,
//			collapsed :true,
//			collapsible:true,
			bodyStyle: {
				padding: '5px',
				border: 1
			},
			fieldDefaults: {
				labelAlign: 'left'
			},
			items: [c2,bs]
		});
var selForm1 = Ext.create('Ext.form.Panel', {
			title:"订舱分票",
			name: 'selForm',
			width:'100%',
			renderTo: "selForm",
//			collapsed :true,
//			collapsible:true,
			bodyStyle: {
				padding: '5px',
				border: 1
			},
			fieldDefaults: {
				labelAlign: 'left'
			},
			items: [selForm,grid]
		});
});
</script>
</html>